package echecs.ia;

import echecs.run.Run;
import javax.swing.JApplet;

public abstract class AEvaluation extends Run {
    //move of the AI
    //variables for the evaluation

    public static float[] posvalues = {0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.01F, 0.02F, 0.03F, 0.03F, 0.02F, 0.01F, 0.0F, 0.0F, 0.0F, 0.01F, 0.04F, 0.04F, 0.04F, 0.04F, 0.04F, 0.04F, 0.01F, 0.0F, 0.0F, 0.03F, 0.04F, 0.06F, 0.06F, 0.06F, 0.06F, 0.04F, 0.02F, 0.0F, 0.0F, 0.03F, 0.04F, 0.06F, 0.08F, 0.08F, 0.06F, 0.04F, 0.03F, 0.0F, 0.0F, 0.03F, 0.04F, 0.06F, 0.08F, 0.08F, 0.06F, 0.04F, 0.03F, 0.0F, 0.0F, 0.02F, 0.04F, 0.06F, 0.06F, 0.06F, 0.06F, 0.04F, 0.02F, 0.0F, 0.0F, 0.01F, 0.04F, 0.04F, 0.04F, 0.04F, 0.04F, 0.04F, 0.01F, 0.0F, 0.0F, 0.0F, 0.01F, 0.02F, 0.03F, 0.03F, 0.02F, 0.01F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F};
    public boolean ababort = false;

    public AEvaluation(JApplet ref) {
        super(ref);
    }

    //evaluate a position
    public void postgenmove() {
        deep--;
        ababort = false;
    }

    public void pregenmove() {
        deep++;
        ababort = false;
        //find checkmat and initialize alphabeta
        if (deep % 2 != 0) {
            minimax[deep] = 2000.0F;
            alphabeta[deep] = 3000.0F;
        } else {
            //human
            minimax[deep] = -2000.0F;
            alphabeta[deep] = -3000.0F;
        }
    }

    public void changeColor() {
        if (color == 1) {
            color = 2;
        } else {
            color = 1;
        }
    }

//    public void nodeValue() {
//        //calculate value of this node
//        if (target == deep) {
//            value = evaluation();
//        } else {
//            changeColor();
//
//            genmove();//TODO
//
//            calculate();
//            changeColor();
//        }
//    }

    public void calculate() {
        value = minimax[deep + 1];
        //change alpha beta field?
        if (deep % 2 != 0) {
            if (value < alphabeta[deep]) {
                alphabeta[deep] = value;
            }
        } else {
            //human
            if (value > alphabeta[deep]) {
                alphabeta[deep] = value;
            }
        }
    }
}
